﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MyBehaviorTree
{
    public class BehaviorTreeBuilder
    {
        public BehaviorTree behaviorTree;
        public BehaviorTreeBuilder()
        {
            behaviorTree = new BehaviorTree();
        }

        public Sequence buildSequence()
        {
            Sequence sequence = new Sequence();
            sequence.blackBoard = behaviorTree.blackBoard;
            return sequence;
        }

        public Selector buildSelector()
        {
            Selector selector = new Selector();
            selector.blackBoard = behaviorTree.blackBoard;
            return selector;
        }

        public ActiveSelector buildActiveSelector()
        {
            ActiveSelector activeSelector = new ActiveSelector();
            activeSelector.blackBoard = behaviorTree.blackBoard;
            return activeSelector;
        }

        public Parallel buildParallel(Parallel.Policy success = Parallel.Policy.RequireAll, Parallel.Policy failure = Parallel.Policy.RequireOne)
        {
            Parallel parallel = new Parallel(success, failure);
            parallel.blackBoard = behaviorTree.blackBoard;
            return parallel;
        }

        public Condition buildCondition(System.Func<BlackBoard, bool> condition)
        {
            FCondition fcondition = new FCondition(condition);
            fcondition.blackBoard = behaviorTree.blackBoard;
            return fcondition;
        }
        public Action buildAction(System.Action<BlackBoard> action)
        {
            FAction faction = new FAction(action);
            faction.blackBoard = behaviorTree.blackBoard;
            return faction;
        }
        public Action buildAction<T>() where T : Action, new()
        {
            Action action = new T();
            action.blackBoard = behaviorTree.blackBoard;
            return action;
        }
    }
}
